package com.wencst.generateJPA.config;

import java.util.LinkedList;
import java.util.List;

import com.wencst.generateJPA.bean.TableBean;
import com.wencst.generateJPA.utils.StringUtils;

/**
 * 核心配置类
 * @author wencst
 *
 */
public class CoreContext {
	//基础java路径
    private String javaShortPath = "src//main//java";
    //父路径
    private String parentPackage;
    //service接口包路径
    private String servicePage;
    //dao接口包路径
    private String daoPage;
    //实体类包路径
    private String domainPage;
    //controller接口包路径
    private String controllerPage;
    //webpage基础文件路径
    private String webShortPath = "src//main//resources//templates";
    //json基础文件路径，包括menus
    private String jsonShortPath = "src//main//resources//templates//json";
    //webpage页面路径
    private String webPage;
    //核心工具类路径
    private String corePage = "com.wencst.generate.service";
    //数据库URL
    private String URL;
    //数据库用户名
    private String username;
    //数据库密码
    private String password;
    //数据库驱动
    private String driver;
    //作者
    private String authorName = "wencst";
    //当前数据库表
    private TableBean tb;
    
    private List<String> tableNames = new LinkedList<>();

    public String getURL() {
		return URL;
	}

	public void setURL(String URL) {
		this.URL = URL;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getAuthorName() {
		return authorName;
	}

	public void setAuthorName(String authorName) {
		this.authorName = authorName;
	}

    public void addTableNames(String className){
    	tableNames.add(className);
    }
 
    public List<String> lisAllTableNames(){
        return tableNames;
    }
    
    public String getJavaShortPath() {
        return javaShortPath;
    }
 
    public void setJavaShortPath(String javaShortPath) {
        this.javaShortPath = javaShortPath;
    }
 
    public String getServicePage() {
    	if(servicePage == null) {
    		servicePage = parentPackage + ".service";
    	}
        return servicePage;
    }
 
    public void setServicePage(String servicePage) {
        this.servicePage = servicePage;
    }
 
    public String getDaoPage() {
    	if (daoPage == null) {
    		daoPage = parentPackage + ".dao";
    	}
        return daoPage;
    }
 
    public void setDaoPage(String daoPage) {
        this.daoPage = daoPage;
    }
 
    public String getControllerPage() {
    	if (controllerPage == null) {
    		controllerPage = parentPackage + ".controller";
    	}
        return controllerPage;
    }
 
    public void setControllerPage(String controllerPage) {
        this.controllerPage = controllerPage;
    }
 
    public String getDomainPage() {
    	if (domainPage == null) {
    		domainPage = parentPackage + ".domain";
    	}
        return domainPage;
    }
 
    public void setDomainPage(String domainPage) {
        this.domainPage = domainPage;
    }
 
    public String getCorePage() {
        return corePage;
    }
 
    public void setCorePage(String corePage) {
        this.corePage = corePage;
    }

	public String getWebPage() {
		return webPage;
	}

	public void setWebPage(String webPage) {
		this.webPage = webPage;
	}

	public String getWebShortPath() {
		return webShortPath;
	}

	public void setWebShortPath(String webShortPath) {
		this.webShortPath = webShortPath;
	}
	
    public String getParentPackage() {
		return parentPackage;
	}

	public void setParentPackage(String parentPackage) {
		this.parentPackage = parentPackage;
	}

	public TableBean getTb() {
		return tb;
	}

	public void setTb(TableBean tb) {
		this.tb = tb;
	}

	public String getDomainRealPath(){
        String path = getProjectPath()+"//"+javaShortPath;
        String domainPath = "";
        if(StringUtils.isBlank(getDomainPage())) {
        	domainPath = getDomainPage().replace(".","//");
        } else {
        	domainPath = parentPackage.replace(".", "//")+"//domain";
        }
        return path+"//"+domainPath;
    }
 
    public String getServiceRealPath(){
        String path = getProjectPath()+"//"+javaShortPath;
        String servicePath = "";
        if(StringUtils.isBlank(getServicePage())) {
             servicePath = getServicePage().replace(".", "//");
        }else{
            servicePath = parentPackage.replace(".","//")+"//service";
        }
        return path+"//"+servicePath;
    }

    public String getServiceImplRealPath(){
        String path = getProjectPath()+"//"+javaShortPath;
        String servicePath = "";
        if(StringUtils.isBlank(getServicePage())) {
             servicePath = getServicePage().replace(".", "//");
        }else{
            servicePath = parentPackage.replace(".","//")+"//service";
        }
        return path+"//"+servicePath+"//impl";
    }
    public String getDaoRealPath(){
        String path = getProjectPath()+"//"+javaShortPath;
        String daoPath = "";
        if(StringUtils.isBlank(getDaoPage())) {
             daoPath = getDaoPage().replace(".", "//");
        }else{
            daoPath = parentPackage.replace(".","//")+"//dao";
        }
        return path+"//"+daoPath;
    }

    public String getControllerRealPath(){
        String path = getProjectPath()+"//"+javaShortPath;
        String controllerPath = "";
        if(StringUtils.isBlank(getControllerPage())) {
             controllerPath = getControllerPage().replace(".", "//");
        }else{
            controllerPath = parentPackage.replace(".","//")+"//controller";
        }
        return path+"//"+controllerPath;
    }

    public String getWebRealPath(){
        String path = getProjectPath()+"//"+webShortPath;
        return path;
    }

    public String getJsonRealPath(){
        String path = getProjectPath()+"//"+jsonShortPath;
        return path;
    }
    
    private String getProjectPath() {
        String path = System.getProperty("user.dir");
        return path.replace("\\","//");
    }
}
